#ifndef MYPROGRESSBARMODEL_H
#define MYPROGRESSBARMODEL_H

#include <QtCore/QAbstractItemModel>
#include <QtCore/qglobal.h>
#include <QString>
#include <QObject>

class MyData
{
//    Q_GADGET

//    Q_PROPERTY(int m_nStep READ step WRITE setStep)
//    Q_PROPERTY(int m_nTotal READ total WRITE setTotal)
//    Q_PROPERTY(QString m_strUuid READ uuid WRITE setUuid)
//    Q_PROPERTY(QString m_strText READ text WRITE setText)

public:
    MyData()
         : m_nStep(-1)
         , m_nTotal(-1)
         , m_strUuid("")
         , m_strText("")
    {}

    int step() const { return m_nStep; }
    void setStep(int value) { m_nStep = value; }

    int total() const { return m_nTotal; }
    void setTotal(int value) { m_nTotal = value; }

    QString uuid() const { return m_strUuid; }
    void setUuid(const QString& value) { m_strUuid = value; }

    QString text() const { return m_strText; }
    void setText(const QString& value) { m_strText = value; }

public:
    int m_nStep;
    int m_nTotal;

    QString m_strUuid;
    QString m_strText;
};

class MyProgressBarModel : public QAbstractListModel
{
    Q_OBJECT

public:
    explicit MyProgressBarModel(QObject *parent = nullptr);
    ~MyProgressBarModel();

    Q_INVOKABLE void insert(int index, const MyData& value);
    Q_INVOKABLE void modified(int index, const MyData& value);
    Q_INVOKABLE void append(const MyData& value);
    Q_INVOKABLE void remove(int index);
    Q_INVOKABLE void clear();

    Q_INVOKABLE int count() const;
    Q_INVOKABLE QString getText(int index);
    Q_INVOKABLE float getValue(int index);
    Q_INVOKABLE int getIndex(const QString& uuid);

public: // interface QAbstractListModel
    int rowCount(const QModelIndex &parent) const Q_DECL_OVERRIDE;
    QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;

signals:
    void countChanged(int arg);
    void myDataChanged(const QString& json);

public slots:
    void updateMydata(const QString& json);


private:
    QList<MyData> m_listData;
};

#endif // MYPROGRESSBARMODEL_H
